﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using HAUtil.DosRunUtil;

namespace HA.ModFlow.Application.DosRun
{
    public class MT3DMSSolution:IRunable
    {



        bool _shouldRun = true;


        public bool ShouldRun
        {
            get
            {
                return _shouldRun;
            }
            set
            {
                _shouldRun = value;
            }
        }




        string _instanceId = "mt3dms";

        public string RunInstanceId
        {
            get
            {
                return _instanceId;
            }
            set
            {
                _instanceId = value;
            }
        }


        string _instanceName = "mt3dms";

        public string RunInstanceName
        {
            get
            {
                return _instanceName;
            }
            set
            {
                _instanceName = value;
            }
        }


        bool _runCatchError;
        public bool RunCatchError
        {
            get
            {
                return _runCatchError;
            }
            set
            {
                _runCatchError = value;
            }
        }

        bool _isHasRun;
        public bool IsHasRun
        {
            get
            {
                return _isHasRun;
            }
            set
            {
                _isHasRun = value;
            }
        }


        bool _isRunRight;
        public bool IsRunRight
        {
            get
            {
                return _isRunRight;
            }
            set
            {
                _isRunRight = value;
            }
        }




        public void OnBeforeRun()
        {
            string solutionPath = ProjectService.DefaultService.GetProjPath(ProjPath.SOLUTION);

            ProjectService.DefaultService.Project.Mt3dmsData.DeleteMT3DFiles(solutionPath );

            ProjectService.DefaultService.Project.Mt3dmsData.WriteFiles(solutionPath);




            //建立文件夹的逻辑   为每个污染物建立一个独立的存放其输出文件的文件夹

            ///输出文件夹的配置  存在则清空 不存在则创建

            //try
            //{
            //    for (int i = 0; i < ProjectSerivce.DefaultService.Project.Mt3dmsData.BasicTransport.SpeciesCollecion.SpeciesCount; i++)
            //    {

            //        if (i >= 0 && i <= 999)
            //        {
            //            string outputDirectoryName = ProjectSerivce.DefaultService.GetMT3DResultDirectoryPath(i);

            //            if (outputDirectoryName.Trim() != "")
            //            {
            //                if (System.IO.Directory.Exists(outputDirectoryName))
            //                {
            //                    System.IO.Directory.Delete(outputDirectoryName, true);//存在 则清空该文件夹
            //                }
            //                if (!System.IO.Directory.Exists(outputDirectoryName))
            //                {
            //                    System.IO.Directory.CreateDirectory(outputDirectoryName);//不存在  则创见文件夹
            //                }

            //            }

            //        }

            //    }

            //}
            //catch
            //{
            //    System.Windows.Forms.MessageBox.Show("为各个污染物建立存放其输出文件的文件夹过程出错！");
            //}




        }

        public void OnEndRun()
        {
          
        }

        public void OnBeforeCommandRun(string id)
        {
            if (id == "MT3DMS")
            {



                string destPath = ProjectService.DefaultService.GetProjPath(ProjPath.SOLUTION) + "mt3dms5b.exe";

                if (!System.IO.File.Exists(destPath))
                {
                    string mt3dmsPath = ApplicationService.DefalutService.GetApplicationPath(ApplicationPath.MODELEXEPATH) + @"mt3dms5b.exe";

                    if (System.IO.File.Exists(mt3dmsPath))
                    {
                        System.IO.File.Copy(mt3dmsPath, destPath);

                    }
                    else
                    {
                        System.Windows.MessageBox.Show("未找到可运行的文件 mt3dms5b.exe");
                    }



                }



            }


            if (id == "postmt3d")
            {

                //string destPath = ProjectSerivce.DefaultService.GetProjPath(ProjPath.SOLUTION) + "postmt3d.exe";
                //if (!System.IO.File.Exists(destPath))
                //{
                //    string mt3dmsPath = ApplicationService.DefalutService.GetApplicationPath(ApplicationPath.EXEPATH) + @"postmt3d.exe";

                //    if (System.IO.File.Exists(mt3dmsPath))
                //    {
                //        System.IO.File.Copy(mt3dmsPath, destPath);

                //    }
                //    else
                //    {
                //        System.Windows.MessageBox.Show("未找到可运行的文件 postmt3d.exe");
                //    }
                //}

            }


           
        }

        public void OnEndCommandRun(string id)
        {
            




        }




    }
}
